package com.example.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.domain.Book;
import com.example.domain.BookEnum;
import com.example.service.BookService;
import com.example.timer.my.ExampleModel;
import com.example.util.Page;
import com.example.util.ResponseData;


@Controller
@RequestMapping("/my")
public class MyController {
	@Value("${ipbatton}")
	private String ipbatton;
	@Autowired
	private BookService bs;
	@RequestMapping(value="/first",method=RequestMethod.POST)
	public @ResponseBody  ResponseData getFirst(@RequestParam("msg") String msg,@RequestParam(value="state",required=false,defaultValue="0" ) int state,HttpServletRequest  request){
		ResponseData rd=new ResponseData();
		rd.setErrorCode("0");
		Book book=new Book();
		book.setName("Book122");
		book.setPrice(23);
		book.setBe(BookEnum.C);
		bs.save(book);
		
		System.out.println(book.getId()+"="+BookEnum.java);
		//Book b=bs.get(book.getId());
		request.getSession().setAttribute("loginname", msg);
	    //int it=1/0;
		rd.setValue("msg="+msg+";state="+state+",ipbatton="+ipbatton+"bs=");
		return rd;
	}
	
	

	@RequestMapping(value="/page",method=RequestMethod.POST)
	public @ResponseBody  ResponseData getPage(@RequestParam("startline") int  start,@RequestParam(value="endline",required=false,defaultValue="0" ) int endline){
		ResponseData rd=new ResponseData();
		rd.setErrorCode("0");
		Page<Book> book=new Page<Book>();
		book.setPageIndex(start);
		book.setMaxResult(endline);
		bs.getBycontains(book);
		rd.setValue(book);
		return rd;
	}
}
